package com.silong.swing.myWindows;

import javax.swing.*;
import javax.swing.text.Position;
import java.awt.*;

/**
 * Created by 龙哥 on 2022-01-17 14:38
 * Silong Software.
 */

public class MyFrameFlowLayout extends JFrame {

    JButton cmdOk;
    JButton cmdClose;

    //构造方法
    public MyFrameFlowLayout(String sTitle, int width, int height){
        init(sTitle, width, height);
    }

    //窗体的初始化
    private void init(String sTitle, int width, int height){

        //1）创建两个按钮
        cmdOk = new JButton("确定");
        cmdClose = new JButton("确定");
        //2）给出当前的窗体面板
        Container window = this.getContentPane();

        //3）设置窗体一些参数
        this.setSize(width, height); //设置面板大小，宽 X 高
        this.setLocationRelativeTo(null); //设置窗体到屏幕中心位置
        this.setTitle(sTitle); //窗口标题
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //退出窗口关闭程序

        //4）添加窗体的布局为流式布局
        window.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); //从左到右
        //创建流式布局从左开始，水平间距 50，垂直间距 30
        FlowLayout flowLayout = new FlowLayout(FlowLayout.LEFT, 50, 30);
        window.setLayout(flowLayout);

        //5）添加两个按钮到面板
        window.add(cmdOk);
        window.add(cmdClose);

        //显示窗体，在类外面进行设置
        //window.setVisible(true);
    }

}
